package com.leonzx.base.config.interceptor;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author:梁亮
 * @Description:
 * @Date: 2018/7/30 14:28
 */
@Configuration
public class WebMvcConfigAdapter implements WebMvcConfigurer {

    //关键，将拦截器作为bean写入配置中
    @Bean
    public AppTokenInterceptor appTokenInterceptor() {
        return new AppTokenInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器
        InterceptorRegistration ir = registry.addInterceptor(appTokenInterceptor());
        // 配置拦截的路径
        ir.addPathPatterns("/api/app/**");
    }
}
